import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { ScenarioConfig } from '../models';

const urlPrefix = "/api/Scenario";
@Injectable({
  providedIn: 'root'
})
export class ScenarioService {

  constructor(private http: HttpClient) { }
  /**
   * 获取项目列表
   */
  getList(): Observable<ScenarioConfig[]> {
    return this.http.get<ScenarioConfig[]>(`${urlPrefix}/GetList`);
  }

  /**
   * 获取项目信息
   * @param id 项目Id
   * @returns 
   */
  get(id: string): Observable<ScenarioConfig> {
    return this.http.get<ScenarioConfig>(`${urlPrefix}/Get?id=${id}`);
  }

  /**
   * 创建项目
   * @param project 
   * @returns 
   */
  create(project: ScenarioConfig): Observable<ScenarioConfig> {
    return this.http.post<ScenarioConfig>(`${urlPrefix}/Create`, { ...project });
  }

  /**
   * 更新项目
   * @param project 
   * @returns 
   */
  updaet(project: ScenarioConfig): Observable<ScenarioConfig> {
    return this.http.put<ScenarioConfig>(`${urlPrefix}/Update`, { ...project });
  }

  /**
   * 删除项目
   * @param id 
   * @returns 
   */
  delete(id: string) {
    return this.http.delete<boolean>(`${urlPrefix}/Delete`, { body: { id } });
  }

}


